import {
	defineStore
} from 'pinia'
import * as API from "../../api/api.js"
export const useExaminationStore = defineStore('useExamination', {
	state: () => {
		return {
			userInfo: null,
      examinationInfo: null,
      // quatoUserInfo: {

      // },
      quatoObj: {
        // "姓名": "name",
        // "性别": "gender",
        // "年龄": "30",
        // "身高": "height",
        "甘油三酯/血胆固醇": "triglyceride",
        "空腹血糖/餐后血糖": "glycaemic",
        "收缩压/舒张压": "bloodPressure",
        "体重": "weight", 
        "BMI": "bmi",
        "体脂肪率": "fatRatio",
        "肌肉量比值": "muscleRatio",
        "基础代谢": "basalMetabolism",
        "总能量代谢": "totalEnergyMetabolism",
        "蛋白质": "protein",
        "体型": "shape"
      }
      // age: "30"
    // basalMetabolism: "1433"
    // bloodPressure: "正常"
    // bmi: "一般"
    // createBy: null
    // createTime: "2024-07-21 13:20:23"
    // examTime: "2024-07-20 13:20:23"
    // fatRatio: "标准健康"
    // gender: "男"
    // glycaemic: "正常"
    // height: "180"
    // lockVersion: null
    // memberId: "809217"
    // muscleRatio: "标准"
    // name: "张三"
    // pageNum: null
    // pageSize: null
    // protein: "10.0"
    // score: "70"
    // shape: "缺乏运动型"
    // totalEnergyMetabolism: "1433"
    // triglyceride: "合适水平"
    // updateBy: null
    // updateTime: null
    // userId: "1811675694938329088"
    // uuid: "0d087dbb3003028d90a852790853f0cf"
    // weight: "50.1"
		}
	},
	actions: {  
    getPhysicalExamination() {
      this.userInfo = uni.getStorageSync("userInfo") ? JSON.parse(uni.getStorageSync("userInfo")) : null
      return API.physicalExamination({userId: this.userInfo.customers.customerId}).then(res => {
        if (res.code === 0) {
          this.examinationInfo = res.data
          return res.data
        } else {
          uni.showToast({
            title: err?.data?.message || "",
            icon: "none"
          })
        }
      }).catch(err => {
        uni.showToast({
          title: err?.data?.message || "获取体检数据失败",
          icon: "none"
        })
      })
    },
  }
})

